function last<T>(a: T[]): T {
    return a[a.length - 1]
}

class StockSpanner {
    prices: number[] = []
    days: number[] = []


    next(price: number) {
        let days = 1
        let i = this.prices.length - 1

        while (i >= 0) {

            if (price >= this.prices[i]) {
                days += this.days[i]
                i -= this.days[i]
            } else {
                break
            }
        }

        this.prices.push(price)
        this.days.push(days)
    }

    static createNew() {
        return new StockSpanner()
    }
};

/**
 * @param {number} price
 * @return {number}
 *;

 /**
 * Your StockSpanner object will be instantiated and called as such:
 * var obj = Object.create(StockSpanner).createNew()
 * var param_1 = obj.next(price)
 */


var obj = Object.create(StockSpanner).createNew()

for (const p of [100, 80, 60, 70, 60, 75, 85]) {
    var param_1 = obj.next(p)
}

console.log([100, 80, 60, 70, 60, 75, 85])
console.log(obj.days)
